#include "../../mqserver/message.hpp"
#include "../../mqcommon/msg.pb.h"
#include <gtest/gtest.h>


std::shared_ptr<MessageManager> managerPtr;
class MsgQueueTest : public testing::Environment
{
public:
    virtual void SetUp() override
    {
        managerPtr = std::make_shared<MessageManager>("ccc");

        managerPtr->initQueueMessage("queue1"); //初始化一个队列
        // managerPtr->initQueueMessage("queue2"); //初始化一个队列
    }
    virtual void TearDown() override
    {
        managerPtr->clear();            //最后测试，删表
    }
};

// TEST(MsgQueueTest, insert)
// {
//     BasicProperty bp;
//     bp.set_id(UUIDHelper::uuid());
//     bp.set_delivery_mode(DeliveryMode::DURABLE);
//     bp.set_routing_key("news.sport.footbool");

//     managerPtr->insert("queue1", &bp, "hello-1", DeliveryMode::DURABLE);
//     managerPtr->insert("queue1", nullptr, "hello-2", DeliveryMode::DURABLE);
//     managerPtr->insert("queue1", nullptr, "hello-3", DeliveryMode::DURABLE);
//     managerPtr->insert("queue1", nullptr, "hello-4", DeliveryMode::DURABLE);
//     managerPtr->insert("queue1", nullptr, "hello-5", DeliveryMode::UNDURABLE);
//     EXPECT_EQ(managerPtr->msgsCount("queue1"), 5);
//     EXPECT_EQ(managerPtr->validCount("queue1"), 4);
//     EXPECT_EQ(managerPtr->totalCount("queue1"), 4);
//     EXPECT_EQ(managerPtr->waitackCount("queue1"), 0);
// }
// TEST(MsgQueueTest, recovery)
// {
//     EXPECT_EQ(managerPtr->msgsCount("queue1"), 4);
//     EXPECT_EQ(managerPtr->validCount("queue1"), 4);
//     EXPECT_EQ(managerPtr->totalCount("queue1"), 4);
//     EXPECT_EQ(managerPtr->waitackCount("queue1"), 0);
// }
// TEST(MsgQueueTest, front)
// {
//     EXPECT_EQ(managerPtr->msgsCount("queue1"), 4);
//     MessagePtr msg = managerPtr->front("queue1");
//     EXPECT_EQ(msg->paylode().body(), "hello-1");
//     EXPECT_EQ(managerPtr->msgsCount("queue1"), 3);
//     EXPECT_EQ(managerPtr->waitackCount("queue1"), 1);

//     msg = managerPtr->front("queue1");
//     EXPECT_EQ(msg->paylode().body(), "hello-2");
//     EXPECT_EQ(managerPtr->msgsCount("queue1"), 2);
//     EXPECT_EQ(managerPtr->waitackCount("queue1"), 2);

//     msg = managerPtr->front("queue1");
//     EXPECT_EQ(msg->paylode().body(), "hello-3");
//     EXPECT_EQ(managerPtr->msgsCount("queue1"), 1);
//     EXPECT_EQ(managerPtr->waitackCount("queue1"), 3);

//     msg = managerPtr->front("queue1");
//     EXPECT_EQ(msg->paylode().body(), "hello-4");
//     EXPECT_EQ(managerPtr->msgsCount("queue1"), 0);
//     EXPECT_EQ(managerPtr->waitackCount("queue1"), 4);
// }
TEST(MsgQueueTest, ack)
{
    // EXPECT_EQ(managerPtr->msgsCount("queue1"), 4);
    // EXPECT_EQ(managerPtr->waitackCount("queue1"), 0);
    // managerPtr->front("queue1");
    // managerPtr->ack("queue1", "ff4d00f3-28ee-8dd3-0000-000000000001");
    EXPECT_EQ(managerPtr->msgsCount("queue1"), 3);
    EXPECT_EQ(managerPtr->validCount("queue1"), 3);
    EXPECT_EQ(managerPtr->totalCount("queue1"), 3);
    EXPECT_EQ(managerPtr->waitackCount("queue1"), 0);
   
}
TEST(MsgQueueTest, destoryQueueMessage)
{
    
}
int main(int argc, char* argv[])
{
    testing::InitGoogleTest(&argc, argv);
    testing::AddGlobalTestEnvironment(new MsgQueueTest);

    return RUN_ALL_TESTS(); 
}